package com.car.activity;

import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;

import com.car.util.AppPreferences;
import com.car.util.VersionUtil;
import com.car.util.AppPreferences.PreferenceKey;
import com.example.car.R;
import com.lidroid.xutils.view.annotation.ViewInject;

public class LoadingActivity extends BaseActivity {

	@ViewInject(R.id.loading_iv_ad)
	ImageView loading_iv_ad;

	private Animation layoutAnimation;

	@Override
	protected int getLayoutId() {

		return R.layout.loading_main;
	}

	@Override
	protected void initParams() {
		// TODO Auto-generated method stub
		layoutAnimation = AnimationUtils.loadAnimation(this,
				R.anim.alpha_loading);
		layoutAnimation.setAnimationListener(new AlphaLayoutListener());
		loading_iv_ad.startAnimation(layoutAnimation);
	}

	class AlphaLayoutListener implements AnimationListener {

		@Override
		public void onAnimationStart(Animation animation) {
			loading_iv_ad.postDelayed(new Runnable() {

				@Override
				public void run() {
					String start_version = AppPreferences.instance().getString(
							PreferenceKey.START_VERSION);
					if (!start_version.equals(VersionUtil.getAppVersionName())) {
						System.out.println(start_version+"start_version");
						System.out.println(VersionUtil.getAppVersionName()+"getAppVersionName()");
						GuideActivity.startActivity(LoadingActivity.this);
						AppPreferences.instance().putString(
								PreferenceKey.START_VERSION,
								VersionUtil.getAppVersionName());
					} else {
						System.out.println(start_version+"start_version");
						System.out.println(VersionUtil.getAppVersionName()+"getAppVersionName()");
						MainActivity.startActivity(LoadingActivity.this);
					}
					finish();
				}
			}, 2 * 1000);

		}

		@Override
		public void onAnimationEnd(Animation animation) {
			// TODO Auto-generated method stub

		}

		@Override
		public void onAnimationRepeat(Animation animation) {
			// TODO Auto-generated method stub

		}

	}

}
